package com.ruoyi.web.controller.consumer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.consumer.domain.UserRoomRel;
import com.ruoyi.consumer.domain.query.TPaymentHyQuery;
import com.ruoyi.consumer.service.IUserRoomRelService;
import com.ruoyi.consumer.service.IVRoomHyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户房产绑定关系
 * @date 2023-10-22
 */
@RestController
@RequestMapping("/userRoom/rel")
public class UserRoomRelController extends BaseController {
    @Autowired
    private IUserRoomRelService userRoomRelService;
    @Autowired
    private IVRoomHyService roomHyService;

    /**
     * 内管端查询用户房产绑定关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserRoomRel userRoomRel) {
        startPage();
        List<UserRoomRel> list = userRoomRelService.selectUserRoomRelListInner(userRoomRel);
        return getDataTable(list);
    }

    /**
     * 内管端获取用户房产绑定关系详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userRoomRelService.selectUserRoomRelById(id));
    }

    /**
     * 刷新供热小区缓存
     */
    @PostMapping("/refreshHeatingLocationCache")
    public AjaxResult refreshHeatingLocationCache() {
        roomHyService.refreshHeatingLocationCache();
        return AjaxResult.success();
    }

    /**
     * 查询当前用户绑定房产信息
     */
    @PostMapping("/selectUserRoomRelList")
    public AjaxResult selectUserRoomRelList() {
        UserRoomRel userRoomRel = new UserRoomRel();
        userRoomRel.setUserId(SecurityUtils.getUserId());
        return AjaxResult.success(userRoomRelService.selectUserRoomRelList(userRoomRel));
    }

    /**
     * 微信端查询支付记录
     */
    @PostMapping("/selectPaymentRecords")
    public AjaxResult selectPaymentRecords(@RequestBody TPaymentHyQuery paymentHyQuery) {
        return AjaxResult.success(userRoomRelService.selectPaymentRecord(paymentHyQuery));
    }

    /**
     * 删除用户房产绑定关系
     */
    @Log(title = "用户房产绑定关系", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody UserRoomRel userRoomRel) {
        return toAjax(userRoomRelService.deleteUserRoomRelById(userRoomRel.getId()));
    }

}
